package com.fanli.bigdata.rec

import org.apache.spark.mllib.recommendation.Rating


object ParseUserAction {
  def parseLine(str: String) : ((String, String), Double) = {
    val fields = str.split(",")
    if ( fields.size == 3 ) {
      ((fields(0), fields(1)), fields(2).toDouble)
    } else {
      (("", ""), 0.0f)
    }
  }

  def parseRating(rating: ((String, String), Double)) = {
    ((rating._1._1, rating._1._2), Rating(rating._1._1.hashCode, rating._1._2.hashCode, rating._2))
  }
}
